home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0429.dms / q0429.adf / libshade / objdef.c < prev    next >
C/C++ Source or Header  |  1991-08-08  |  2KB  |  115 lines

  1. /*
  2.  * objdef.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: objdef.c,v 4.0 91/07/17 14:46:38 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    objdef.c,v $
  19.  * Revision 4.0  91/07/17  14:46:38  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23.  
  24. #include "rayshade.h"
  25. #include "options.h"
  26. #include "stats.h"
  27.  
  28. static Geom *Objects = NULL;        /* named objects */
  29. Geom *World;                /* top-level object */
  30.  
  31.  
  32. /*
  33.  * Return pointer to named object, NULL if no such object has been defined.
  34.  */
  35. Geom *
  36. GeomGetNamed(name)
  37. char *name;
  38. {
  39.     Geom *otmp;
  40.     for (otmp = Objects; otmp; otmp = otmp->next)
  41.         if (strcmp(name, otmp->name) == 0)
  42.             return otmp;
  43.     return (Geom *)NULL;
  44. }
  45.  
  46. /*
  47.  * Add object to list of defined objects.  At this point, the object has
  48.  * been converted to the correct type, and obj->next is either NULL or
  49.  * garbage.
  50.  */
  51. void
  52. GeomAddToDefined(obj)
  53. Geom *obj;
  54. {
  55.     obj->next = Objects;
  56.     Objects = obj;
  57.     if (Options.verbose)
  58.         AggregatePrintInfo(obj, Stats.fstats);
  59.     else
  60.         AggregatePrintInfo(obj, (FILE *)NULL);
  61. }
  62.  
  63. /*
  64.  * Return a copy of the named object.
  65.  */
  66. Geom *
  67. GeomCopyNamed(name)
  68. char *name;
  69. {
  70.     Geom *child;
  71.  
  72.     child = GeomGetNamed(name);
  73.     if (child == (Geom *)NULL)
  74.         RLerror(RL_PANIC, "There is no object named \"%s\".", name);
  75.     child = GeomCopy(child);
  76.     return child;
  77. }
  78.  
  79. void
  80. WorldSetup()
  81. {
  82.     extern GeomList *Defstack;
  83.  
  84.     /*
  85.      * Define World object, if not done previously.
  86.      */
  87.     if (World == (Geom *)NULL) {
  88.         World = Defstack->obj;    /* World is topmost object on stack */
  89.         if (Defstack->next)
  90.             RLerror(RL_ABORT, "Geom def stack is screwey.\n");
  91.         World->prims = AggregateConvert(World, World->next);
  92.     }
  93.  
  94.     GeomComputeBounds(World);
  95.  
  96.     /*
  97.      * Complain if there are no primitives to be rendered.
  98.      */
  99.     if (World->prims == 0) {
  100.         RLerror(RL_PANIC, "Nothing to be rendered.\n");
  101.     }
  102. }
  103.  
  104. /*
  105.  * Main ray-spwaning routine required by libray
  106.  */
  107. int
  108. TraceRay(ray, hitlist, mindist, maxdist)
  109. Ray *ray;
  110. HitList *hitlist;
  111. Float mindist, *maxdist;
  112. {
  113.     return intersect(World, ray, hitlist, mindist, maxdist);
  114. }
  115.